﻿require(["./config"], function() {
	require(["jquery","cookie"], function($) {
		
		function denglu(){
			this.go();
			$.cookie.json = true;
		}
		denglu.prototype={
			constructor:denglu,
			go(){
				let sub=$(".main>.center>.right>.btn");
				sub.on("click",()=>{
					let u=$(".in1").val();
					let p=$(".in2").val();
					$.post("http://localhost/api/login.php",
							{
								username:u,
								password:p
							},(res)=>{
								res=JSON.parse(res);
								let data=res.code;
								console.log(data);
								if(data==1)
								{
									alert("登录成功");
									location="/index.html";
									let welcome = [u];
									$.cookie("welcome", welcome, {expires: 7, path: "/"})

								}
								else
								{
									alert("用户名或密码不正确");
								}
							});
				});
			}
			
		}
		new denglu();
	})
})